package approve.action;

import java.util.List;

import model.pojo.Employee;
import resource.pojo.Approvedoc;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import approval.dao.ApproveDocumentDAO;

public class My_App_ApprovedDocument extends Activity {
	String database = "admin";

	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
		}
		return database;
	}

	public String getLang() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			lang = extras.getString("lang");
		}
		return lang;
	}

	String lang = "EN";
	Approvedoc AppDoc = null;
	Employee emp = null;
	ListView list;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_app_approvedocument);
		getDatabase();
		emp = (Employee) getIntent().getExtras().get("em");
		list = (ListView) findViewById(R.id.lst_myapprovedocument);
		list.setAdapter(new ArrayAdapter<Approvedoc>(this,
				android.R.layout.simple_list_item_1, getListAppovedDocument()));
		list.setOnItemClickListener(viewForm);
	}

	private OnItemClickListener viewForm = new OnItemClickListener() {
		public void onItemClick(android.widget.AdapterView<?> lstAppDoc,
				android.view.View arg1, int arg2, long arg3) {
			Approvedoc AppDoc = (Approvedoc) lstAppDoc.getItemAtPosition(arg2);
			if (AppDoc.getiDTypeDoc() == 16) {
				Intent intent = new Intent(My_App_ApprovedDocument.this,
						My_viewform16.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				startActivity(intent);
			} else if (AppDoc.getiDTypeDoc() == 15) {
				Intent intent = new Intent(My_App_ApprovedDocument.this,
						My_ViewForm15_tab.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				startActivity(intent);
			} else if (AppDoc.getiDTypeDoc() < 11) {
				Intent intent = new Intent(My_App_ApprovedDocument.this,
						My_ViewForm_Lessthan10.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				startActivity(intent);
			} else if (AppDoc.getiDTypeDoc() == 11) {
				Intent intent = new Intent(My_App_ApprovedDocument.this,
						My_ViewForm11.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				startActivity(intent);
			} else if (AppDoc.getiDTypeDoc() == 12) {
				Intent intent = new Intent(My_App_ApprovedDocument.this,
						My_ViewForm12.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				startActivity(intent);
			} else if (AppDoc.getiDTypeDoc() == 13) {
				Intent intent = new Intent(My_App_ApprovedDocument.this,
						My_ViewForm13.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				startActivity(intent);
			} else {
				Intent intent = new Intent(My_App_ApprovedDocument.this,
						My_ViewForm14.class);
				intent.putExtra("AppDoc", AppDoc);
				intent.putExtras(getIntent().getExtras());
				startActivity(intent);
			}

		};
	};

	public List<Approvedoc> getListAppovedDocument() {
		System.out.println("aaaaa");
		System.out.println("lst1"
				+ ApproveDocumentDAO.getAllDoc(1, "", "", emp.getIdemployee(),
						getDatabase()));
		return ApproveDocumentDAO.getAllDoc(1, "", "", emp.getIdemployee(),
				getDatabase());

	}

}
